int motorG=7;//Motor del Gancho
int motorG1=8;//Motor del gancho
const int milivolts=0,milivoltsD=0,milivoltsI=0,signal=A0,signalD=A1,signalI=A2;
int i=0;
int j=100;
int estado_boton = 0; 
int pwm= 9; 
const int motor1=3;
const int motor2=4;
int a=0;
int l1=0;
int l2=0;
int l3=0;
int l4=0;
int pr1=0;
int pr2=0;
int pr3=0;
int pr4=0;
char val;
void setup ();
{
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
  pinMode(signal, INPUT);
  Serial.begin(9600);
}

void loop();
{
{
  if( Serial.available() ){
  val = Serial.read();
}
    if( val=='a'){
      l1++;
      pr1=l1%2;
      digitalWrite(motor1,HIGH);
      digitalWrite(motor2,HIGH);
   
    if(pr1==0){
       digitalWrite(motor1,LOW);
       digitalWrite(motor2,LOW);
     }
    }
    
    if( val=='b'){
       l2++;
      pr2=l2%2;
      digitalWrite(motor1,LOW);
      digitalWrite(motor2,LOW);   
   
    if(pr2==0){
       digitalWrite(motor1,LOW);
       digitalWrite(motor2,LOW);
     }
       
    }
    
     if( val=='c'){
       l3++;
      pr3=l3%2;
      digitalWrite(motor1,HIGH);
      digitalWrite(motor2,LOW);
   
   
    if(pr3==0){
      digitalWrite(motor1,LOW);
      digitalWrite(motor2,LOW);
     }
    }
    
    
     if( val=='d'){
       l4++;
      pr4=l4%2;
      digitalWrite(motor1,LOW);
      digitalWrite(motor2,HIGH);
   
    if(pr4==0){
       digitalWrite(motor1,LOW);
       digitalWrite(motor2,LOW);
     }
    }
    
     
   val=0;
  
  milivotls=analogRead(signal);
  if(milivolts==10)
  {
  do{
  for(i;i<=j;i++;)
  {
    digitalWrite(motor1, HIGH);
    digitalWrite(motor2, HIGH);
    delay(10)  ;
    digitalWrite(motor1, LOW);
    digitalWrite(motor2, LOW);
    milivolts=analogRead(signal);
    if(milivolts==20) FRojo(i,j);
    if(milivolts==30) FAzul(i,j);    
  }
  digitalWrite(motor1, HIGH);
  digitalWrite(motor2, LOW);
  delay(100);
  i=0;
  j=j-10;
  }while(milivolts==50)
}

void FRojo (int x, int y)
{
  do{
  for(x;x<=y;x++)
      {
        milivoltsD=analogRead(SignalD);
        digitalWrite(motor1, HIGH);
        digitalWrite(motor2, HIGH);
        delay(10);
        digitalWrite(motor1, LOW);
        digitalWrite(motor2, LOW);
        if(milivotsD==20)
        {
         digitalWrite(motorG, HIGH);
         digitalWrite(motorG1, LOW);
         delay(20);
         digitalWrite(motorG, LOW);
         digitalWrite(motorG1, LOW);  
        }
        	else if(milivolts==40)
	{
	 digitalWrite(motorG, LOW);
         digitalWrite(motorG1, HIGH);
         delay(20);
         digitalWrite(motorG, LOW);
         digitalWrite(motorG1, LOW);
	}
      }
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);
      delay(100);
      x=0;
      y=y-10;
   }while(milivolts==50)
}

void FAzul (int x, int y)
{
  do{
  for(x;x<=y;x++)
      {
        milivoltsD=analogRead(SignalD);
        digitalWrite(motor1, HIGH);
        digitalWrite(motor2, HIGH);
        delay(10);
        digitalWrite(motor1, LOW);
        digitalWrite(motor2, LOW);
        if(milivotsD==20)
        {
         digitalWrite(motorG, HIGH);
         digitalWrite(motorG1, LOW);
         delay(20);
         digitalWrite(motorG, LOW);
         digitalWrite(motorG1, LOW);  
        }
        	else if(milivolts==40)
	{
	 digitalWrite(motorG, LOW);
         digitalWrite(motorG1, HIGH);
         delay(20);
         digitalWrite(motorG, LOW);
         digitalWrite(motorG1, LOW);
	}
      }
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);
      delay(100);
      x=0;
      y=y-10;
  }while(milivolts==50)
}
